package com.usian.behavior.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.behavior.ApUnlikesBehaviorControllerApi;
import com.usian.behavior.service.ApUnlikesBehaviorService;
import com.usian.model.behavior.dtos.UnLikesBehaviorDto;
import com.usian.model.behavior.pojos.ApUnlikesBehavior;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/un_likes_behavior")
public class ApUnlikesBehaviorController implements ApUnlikesBehaviorControllerApi {

   @Autowired
   private ApUnlikesBehaviorService apUnlikesBehaviorService;

    @Override
    @PostMapping("/readBehavior")/*保存不喜欢的行为*/
    public ResponseResult readBehavior(@RequestBody UnLikesBehaviorDto dto) {
        return apUnlikesBehaviorService.readBehavior(dto);
    }

    @Override/*根据行为实体id和文章id查询不喜欢行为*/
    @GetMapping("/one")
    public ApUnlikesBehavior findUnLikeByArticleIdAndEntryId(@RequestParam("entryId")Integer entryId,@RequestParam("articleId") Long articleId) {

        ApUnlikesBehavior apUnlikesBehavior = apUnlikesBehaviorService.getOne(Wrappers.<ApUnlikesBehavior>lambdaQuery().eq(ApUnlikesBehavior::getEntryId, entryId)
                .eq(ApUnlikesBehavior::getArticleId, articleId));

        return apUnlikesBehavior;
    }
}
